// mircoApp/new-auction/new_auction_Bidding_detail/new_auction_Bidding_detail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    pageTitle: "",
    list: [],
    selectItem: null,
    name: '',

    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.tag) {
      this.setData({
        name: options.tag
      })
    }
    wx.setNavigationBarTitle({
      title: this.data.name == 'new_auction_Bidding_detail' ? '参拍明细' : '委拍明细',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.isLoadMore) {
      this.getMoreData();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  closePopup() {
    this.setData({
      show: false
    })
  },
  async cancelAuction(e) {
    let {
      id
    } = e.detail;
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.new-auction.frontend.auction.cancelAuction"),
      data: {
        id: e.id
      }
    })
    if (data.result) {
      app.tips(data.msg)
      this.getData();
    } else {
      app.tips(data.msg)
    }
  },
  pickUpChild(e) {
    if (this.data.name == "new_auction_Auction_details") {
      return;
    }
    let {
      id,
      item
    } = e.detail;
    this.setData({
      show: true,
      selectItem: item
    })
  },
  async pickUpChild_popup(e) {
    let json = {
      new_auction_id: e.detail.id,
      new_auction_pick_num: e.detail.value
    };
    wx.navigateTo({
      url: `/packageD/buy/myOrder_v2/myOrder_v2?tag=new_auction&new_auction_id=${json.new_auction_id}&new_auction_pick_num=${json.new_auction_pick_num}`,
    })
    this.setData({
      show: false,
      selectItem: null
    })
  },
  async getData() {
    let urlstr = "plugin.new-auction.frontend.auction";
    if (this.data.name == "new_auction_Auction_details") {
      urlstr = "plugin.new-auction.frontend.entrust";
    }
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss(urlstr),
      data: {
        page: 1
      }
    })
    console.log(data)
    if (data.result) {
      this.setData({
        list: data.data.data,
        isLoadMore: true,
        total_page: data.data.last_page
      })
      console.log(this.data.list)
    } else {
      this.data.isLoadMore = false;
      app.tips(data.msg)
    }
  },
  async getMoreData() {
    if (!this.data.isLoadMore) return;
    this.data.isLoadMore = false;
    if (this.data.page >= this.data.total_page) {
      return;
    } else {
      let urlstr = "plugin.new-auction.frontend.auction";
      if (this.data.name == "new_auction_Auction_details") {
        urlstr = "plugin.new-auction.frontend.entrust";
      }
      this.setData({
        page: this.data.page + 1
      })
      let {
        data
      } = await app._postNetWork({
        url: app.getNetAddresss(urlstr),
        data: {
          page: this.data.page
        }
      })
      this.data.isLoadMore = true;
      if (data.result) {
        this.setData({
          list: this.data.list.concat(data.data.data),
        })
      } else {
        this.data.isLoadMore = false;
        app.tips(data.msg);
      }
    }
  }
})